package com.liao.liaowenlong.service;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import com.liao.liaowenlong.R;

public class IntentServiceActivity extends AppCompatActivity implements View.OnClickListener {

    private Button btn_1;
    private Button btn_2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_intent_service);
        initView();
    }

    private void initView() {
        btn_1 = (Button) findViewById(R.id.btn_1);
        btn_2 = (Button) findViewById(R.id.btn_2);

        btn_1.setOnClickListener(this);
        btn_2.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(this, MyIntentService.class);
        switch (v.getId()) {
            case R.id.btn_1:
                intent.putExtra("data1", "data1");
                break;
            case R.id.btn_2:
                intent.putExtra("data2", "data2");
                break;
        }
        startService(intent);
    }
}
